package basic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.UUID;
import java.util.WeakHashMap;

public class test {
	public static Test1	t	= new Test1();
	public static int	a	= 0;
	public static int	b;
	public static void main(String[] args) throws Exception {
		//
		System.out.println(test.a);
		System.out.println(test.b);
		System.out.println(test.t);
		System.out.println(test.a);
		System.out.println(test.b);
		System.out.println(test.t);
		System.out.println();
		//
		int[] arr1 = {1, 2};
		System.out.println(31 * 32);
		System.out.println(Arrays.hashCode(arr1));
		//
		String str1 = "a".replace('a', 'b').replace("b", "a");
		HashMap map1 = new HashMap();
		map1.put("a", "b");
		map1.put(str1, "1");
		System.out.println(map1);
		IdentityHashMap map2 = new IdentityHashMap();
		map2.put("a", "b");
		map2.put(str1, "1");
		System.out.println(map2);
		WeakHashMap map3 = new WeakHashMap();
		map3.put("a", "b");
		map3.put(str1, "1");
		System.out.println(map3);
		//
		UUID uuid = new UUID(System.currentTimeMillis(), System.nanoTime());
		System.out.println(uuid.toString());
		UUID uuid2 = UUID.randomUUID();
		System.out.println(uuid2);
		//
		tryCatchFinallyTest();
		//
		boolean flag = surpriseTheProgrammer(true);
		System.out.println(flag);
		flag = surpriseTheProgrammer(false);
		System.out.println(flag);
	}

	/**
	 * try Catch Finally Test
	 */
	public static void tryCatchFinallyTest() {
		try {
			int i = 1 + 1;
			String hi = "hello world";
			System.out.println(i + ": " + hi);
			return;
		} catch (Exception ex) {

		} finally {
			System.out.println("this code run from finally");
		}
		System.out.println("you are right");// not execute
	}

	static boolean surpriseTheProgrammer(boolean bVal) {
		while (bVal) {
			try {
				return true;
			} finally {
				break;
			}
		}
		return false;
	}

	static class Test1 {
		Test1() {
			test.a++;
			test.b++;
		}
	}
}
